# Contributor: Díaz Urbaneja Diego <sodomon2@gmail.com>
# Maintainer: Díaz Urbaneja Diego <sodomon2@gmail.com>
pkgname=ppsspp
pkgver=1.12.3
pkgrel=1
pkgdesc="PPSSPP - a fast and portable PSP emulator"
url="https://www.ppsspp.org/"
arch="x86 x86_64 ppc64le" # other arches fail to build
_armips_commit="7885552b208493a6a0f21663770c446c3ba65576"
_discord_commit="3d3ae7129d17643bc706da0a2eea85aafd10ab3a"
_glslang_commit="dc11adde23c455a24e13dd54de9b4ede8bdd7db8"
_spirv_cross_commit="9acb9ec31f5a8ef80ea6b994bb77be787b08d3d1"
_rapidjson_commit="73063f5002612c6bf64fe24f851cd5cc0d83eef9"
_miniupnp_commit="3a87be33e797ba947b2b2a5f8d087f6c3ff4d93e"
license="GPL-2.0-only"
makedepends="
	cmake
	ffmpeg4-dev
	glew-dev
	libzip-dev
	mesa-dev
	python3
	qt5-qtbase-dev
	qt5-qtmultimedia-dev
	samurai
	sdl2-dev
	snappy-dev
	zlib-dev
	zstd-dev
	"
source="ppsspp-$pkgver.tar.gz::https://github.com/hrydgard/ppsspp/archive/v$pkgver.tar.gz
	ppsspp-$pkgver-armips.tar.gz::https://github.com/Kingcom/armips/archive/$_armips_commit.tar.gz
	ppsspp-$pkgver-discord-rpc.tar.gz::https://github.com/discordapp/discord-rpc/archive/$_discord_commit.tar.gz
	ppsspp-$pkgver-glslang.tar.gz::https://github.com/hrydgard/glslang/archive/$_glslang_commit.tar.gz
	ppsspp-$pkgver-SPIRV-Cross.tar.gz::https://github.com/KhronosGroup/SPIRV-Cross/archive/$_spirv_cross_commit.tar.gz
	ppsspp-$pkgver-rapidjson.tar.gz::https://github.com/Tencent/rapidjson/archive/$_rapidjson_commit.tar.gz
	ppsspp-$pkgver-miniupnp.tar.gz::https://github.com/hrydgard/miniupnp/archive/$_miniupnp_commit.tar.gz
	ppsspp-version.patch
	system-zstd.patch
	"
options="!check" # make check not implemented

prepare() {
	default_prepare
	# adding submodules needed by ppsspp
	mv "$srcdir/"armips-$_armips_commit/* "$builddir"/ext/armips/
	mv "$srcdir/"discord-rpc-$_discord_commit/* "$builddir"/ext/discord-rpc/
	mv "$srcdir/"glslang-$_glslang_commit/* "$builddir"/ext/glslang/
	mv "$srcdir/"rapidjson-$_rapidjson_commit/* "$builddir"/ext/rapidjson/
	mv "$srcdir/"SPIRV-Cross-$_spirv_cross_commit/* "$builddir"/ext/SPIRV-Cross/
	mv "$srcdir/"miniupnp-$_miniupnp_commit/* "$builddir"/ext/miniupnp/
}

build() {
	cmake -B build-qt -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_BUILD_TYPE=Release \
		-DUSE_SYSTEM_FFMPEG=ON \
		-DUSE_SYSTEM_LIBPNG=ON \
		-DUSE_SYSTEM_LIBSDL2=ON \
		-DUSE_SYSTEM_LIBZIP=ON \
		-DUSE_SYSTEM_SNAPPY=ON \
		-DUSE_SYSTEM_ZSTD=ON \
		-DUSING_QT_UI=ON
	cmake --build build-qt
}

package() {
	DESTDIR="$pkgdir" cmake --install build-qt
}


sha512sums="
fe5f5b150cc06ecca68c592fa19396d9a6e573c67da9be0ba98a3db975b0efcb6de694ac224543beaea2a3eb4952d45459e850d6c2f0fe6668536325dd449d38  ppsspp-1.12.3.tar.gz
2a94e2c7b7280c00a39c8fc92d81ed15fc4b3270a124ef882e3cd8878db6ec827aefa06b0e646a60916636a95e4ebfa886e9878ba70c6bcfcd048def457368be  ppsspp-1.12.3-armips.tar.gz
17fb5de5d5afea9b7e0cdc116d5e3611b147eb2cde3a295a1a4ceb688bceb93d54feb2e479d511ce39d53a1380462a75dcdf6be9ddc2cece9d44b7f8ff7504af  ppsspp-1.12.3-discord-rpc.tar.gz
39b7fd1332dc2f6e29c920961e2a48a33cb7fb36753a0ee5ea8897cb2ad11cec67808ec671cd1bdecbb03eb17f4e83a711013bb20a8cc0831879eb9fbe432bcd  ppsspp-1.12.3-glslang.tar.gz
be77131814691dfbe65de3a2d3ea65de98c7169824997056637bbce39485327ff0f64e7eed8588237615948824e1f9dff1d083472b8cbccd3748a52379411e4e  ppsspp-1.12.3-SPIRV-Cross.tar.gz
3472e129e710bf5343b8b27a61581a1480c8096493e466440b62702d8b5353745d561931f72b5405a736ad92525be3843ea1cf4b5ea5839721cc6d6b358f19bc  ppsspp-1.12.3-rapidjson.tar.gz
f86f558699e75e7f8a58bbb5e94c2a32d703432cef05ffeac0da129113a1fe485cc5ad43b1fcfda11ee1ee398fa434511eccc37633eb5d3dfe8af864097669de  ppsspp-1.12.3-miniupnp.tar.gz
8603418a1003f29b6bf35bf74da08939ff5fab71fa18d94aadb254ac3ceee793f16ee5c815d1cea018bb522281d102c78318046baefeee18ff595da509267970  ppsspp-version.patch
db35533cc5700905b597a5fea9add06608e4f393ea52ab3eac68be48254d299f43aa881e3767c253ba21bd3f043826aab7ff0495a67ef7587b300aa387a03f37  system-zstd.patch
"
